/*
 * @Description: 资源信息 - 接口
 * @Author: DHL
 * @Date: 2022-02-14 21:37:31
 * @LastEditors: DHL
 * @LastEditTime: 2022-08-12 10:15:39
 */

import { $get, $post, $put } from '/@/utils/http'
import { ContentTypeEnum } from '/@/constant/http'
import {
  ResourceListResultModel,
  ResourceModel,
  ResourcePageParams,
  ResourcePageResultModel,
  ResourceResultModel
} from './model/resourceModel'
import { Result } from '/@/model/baseModel'

/**
 * 分页查询
 */
export const apiResourceSearch = (searchParams: ResourcePageParams) =>
  $get<ResourcePageResultModel>({
    url: '/sys/twbResource/search',
    params: searchParams
  })

/**
 * 不分页查询
 * @param searchParams
 * @returns
 */
export const apiResourceSearchList = (searchParams: ResourcePageParams) =>
  $get<ResourceListResultModel>({
    url: '/sys/twbResource/searchList',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const apiResourceGetById = (id: string) =>
  $get<ResourceResultModel>({
    url: '/sys/twbResource/getById',
    params: { id: id }
  })

/**
 * 保存信息
 */
export const apiResourceSave = (saveParams: ResourceModel) =>
  $post<ResourceResultModel>({
    url: '/sys/twbResource/save',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 更新信息
 */
export const apiResourceUpdateById = (updateParams: ResourceModel) =>
  $put<ResourceResultModel>({
    url: '/sys/twbResource/updateById',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })

/**
 * 根据ID删除信息
 */
export const apiResourceDeleteById = (id: string) =>
  $post<ResourceResultModel>({
    url: '/sys/twbResource/deleteById',
    params: { id: id }
  })

/**
 * 批量删除信息
 */
export const apiResourceBatchDeleteByIds = (ids: string) =>
  $post<ResourceResultModel>({
    url: '/sys/twbResource/batchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 根据ID逻辑删除信息
 */
export const apiResourceLogicDeleteById = (id: string) =>
  $post<ResourceResultModel>({
    url: '/sys/twbResource/logicDeleteById',
    params: { id: id }
  })

/**
 * 批量逻辑删除
 */
export const apiResourceLogicBatchDeleteByIds = (ids: string) =>
  $post<ResourceResultModel>({
    url: '/sys/twbResource/logicBatchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 绑定资源api
 * @param resourceId
 * @param apiIds
 * @returns
 */
export const apiResourceSaveResourceApi = (resourceId: string, apiIds: string) =>
  $post<Result<string>>({
    url: '/sys/twbResource/saveResourceApi',
    params: { resourceId: resourceId, apiIds: apiIds }
  })

/**
 * 查询机构、角色经办权限树
 * @param searchParams
 *        type: 类型（0，机构；1，角色）
 *        bizId: 业务ID,
 *        projectId: 项目ID
 */
export const apiResourceSearchAuthResourceTree = (searchParams: {
  type: number
  bizId: string
  projectId: string
}) =>
  $get<ResourceListResultModel>({
    url: '/sys/twbResource/searchAuthResourceTree',
    params: searchParams
  })

/**
 * 查询角色授权权限树
 * @param searchParams
 */
export const apiResourceSearchRoleAccreditResourceTree = (searchParams: {
  roleId: string
  projectId: string
}) =>
  $get<ResourceListResultModel>({
    url: '/sys/twbResource/searchRoleAccreditResourceTree',
    params: searchParams
  })


/**
 * 更新资源状态
 * @param resId 
 * @param resStatus 
 * @returns 
 */
export const apiResourceUpdateStatusById = (resId: string, resStatus: string) =>
  $post<ResourceListResultModel>({
    url: '/sys/twbResource/updateStatusById',
    params: {
      id: resId,
      status: resStatus
    }
  })